# -*- coding: utf-8 -*-
# @Time: 2025/6/29 21:52
# @Author: wzd
# @Email: 2146333089@qq.com
# @File: parse_content.py
def enhance_content(md_file):
    """增强Markdown内容提取"""
    from markdown_it import MarkdownIt
    from mdformat.renderer import RenderContext, MDRenderer

    # 解析Markdown结构
    md = MarkdownIt().parse(Path(md_file).read_text(encoding="utf-8"))
    renderer = MDRenderer()
    tokens = renderer.render(md, RenderContext())

    # 提取关键元素
    elements = {
        "headings": [],
        "tables": [],
        "code_blocks": [],
        "images": []
    }

    for token in tokens:
        if token.type == "heading":
            elements["headings"].append({
                "level": token.tag[1],
                "text": token.content
            })
        elif token.type == "table":
            elements["tables"].append(token.content)
        # ... 其他元素处理

    return elements
